package com.example.fbi_text.bean;

import android.os.Parcel;
import android.os.Parcelable;

public class Product implements Parcelable {
    private int id;
    private String name;
    private String price;
    private int sales;
    private int reviews;
    private String description;
    private int imageResId;

    public Product() {}

    public Product(int id, String name, String price, int sales, int reviews, String description, int imageResId) {
        this.id = id;
        this.name = name;
        this.price = price != null ? price : "0.00";
        this.sales = sales;
        this.reviews = reviews;
        this.description = description;
        this.imageResId = imageResId;
    }

    // Parcelable实现
    protected Product(Parcel in) {
        id = in.readInt();
        name = in.readString();
        price = in.readString();
        sales = in.readInt();
        reviews = in.readInt();
        description = in.readString();
        imageResId = in.readInt();
    }

    public static final Creator<Product> CREATOR = new Creator<Product>() {
        @Override
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        @Override
        public Product[] newArray(int size) {
            return new Product[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeString(price);
        dest.writeInt(sales);
        dest.writeInt(reviews);
        dest.writeString(description);
        dest.writeInt(imageResId);
    }

    // Getters and Setters
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getPrice() { return price; }
    public void setPrice(String price) { this.price = price; }
    public int getSales() { return sales; }
    public void setSales(int sales) { this.sales = sales; }
    public int getReviews() { return reviews; }
    public void setReviews(int reviews) { this.reviews = reviews; }
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    public int getImageResId() { return imageResId; }
    public void setImageResId(int imageResId) { this.imageResId = imageResId; }
}
